import { SystemConstant } from '@/constants/SystemConstant';
import { ThemeEnum } from '@/types/global.d';
import { defineStore } from 'pinia';
import LocalStorageUtil from '@/utils/LocalStorageUtil.ts';
import EMediaQueryUtil from '@/utils/EMediaQueryUtil.ts';

export const useSystemStore = defineStore('useSystemStore', {
    state: () => {
        return {
            // 如果是手机，那 currentTheme = ThemeEnum.PHONE
            currentTheme: (() => {
                const theme = LocalStorageUtil.get<ThemeEnum>(
                    SystemConstant.THEME,
                    ThemeEnum.LIGHT,
                    (str) =>
                        Object.values(ThemeEnum).includes(str as ThemeEnum),
                );

                if (EMediaQueryUtil.is('phone')) {
                    return ThemeEnum.PHONE;
                } else {
                    return theme;
                }
            })(),
            currentLocale: LocalStorageUtil.get<'zhCN' | 'en'>(
                SystemConstant.Locale,
                'zhCN',
                (str) => ['zhCN', 'en'].includes(str),
            ),
            percentage: 0,
        };
    },
});
